﻿using BuildingBlocks.Messaging.Events;
using Catalog.API.Products.LockProduct;
using MassTransit;

namespace Catalog.API.Products.Consumers
{
    public class OrderCreateEvent2Consumer(ISender sender,ILogger<OrderCreateEvent2Consumer> logger) : IConsumer<OrderCreateEvent2>
    {
        public async Task Consume(ConsumeContext<OrderCreateEvent2> context)
        {
            // TODO: Create new order and start order fullfillment process
            logger.LogInformation("Integration Event handled: {IntegrationEvent}", context.Message.GetType().Name);

            var command = MapToLockProductCommand(context.Message);
            await sender.Send(command);
        }

        private LockProductCommand MapToLockProductCommand(OrderCreateEvent2 message)
        {
            var command = new LockProductCommand(message.OrderId, message.OrderName, message.ProductId, message.ProductName, message.Qty) ;
            return command; 
        }
    }
}
